package cn.ffcs.product.web;

import java.io.File;
import java.sql.ResultSet;
import java.util.*;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.dao.DataIntegrityViolationException;

import com.opensymphony.xwork2.ActionContext;

import cn.ffcs.base.web.BaseAction;
import cn.ffcs.base.web.PageControl;
import cn.ffcs.common.model.Attach;
import cn.ffcs.common.service.IAttachService;
import cn.ffcs.organ.model.LinkMethod;
import cn.ffcs.organ.model.Person;
import cn.ffcs.organ.service.LinkMethodService;
import cn.ffcs.organ.service.IPersonService;
import cn.ffcs.product.model.Product;
import cn.ffcs.product.model.ProductManager;
import cn.ffcs.product.model.ProductReference;
import cn.ffcs.product.service.IProductReferenceService;
import cn.ffcs.product.service.IProductService;
import cn.ffcs.ref.model.ProductRefSort;
import cn.ffcs.ref.service.IProductRefSortService;
import cn.ffcs.security.model.User;
import cn.ffcs.security.model.UserResource;
import cn.ffcs.sort.model.ProductSort;
import cn.ffcs.sort.service.IProductSortService;
import cn.ffcs.system.dict.model.Dict;
import cn.ffcs.system.dict.model.DictType;
import cn.ffcs.system.dict.service.DictService;
import cn.ffcs.system.dict.service.DictTypeService;
import cn.ffcs.util.MyList;
import cn.ffcs.util.context.ApplicationContextUtil;

/**
 * 福建省产品目录实体类：定义基本属性<br/>
 * <table>
 * <tr>
 * <td>负责人/principal:</td>
 * <td colspan="2">g.huangjx</td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:2009-2-26</td>
 * <td>修改人:g.huanjx</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr>
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * @author g.huangjx
 * @version $Id$
 */
public class ProductAction<D extends Product> extends BaseAction<D>
{
    private static final int BUFFER_SIZE = 512 * 1024;
    /** 动态网路标识 */
    private static final long serialVersionUID = -8246991977511117520L;
    /** 福建省产品目录 **/
    private D product;
    /** 福建省产品目录结果集 **/
    private List<D> products;
    /** 附件服务 **/
    private IAttachService attachService;
    /** 附件上传 **/
    private List<File> uploads;
    /** 上传附件名称 **/
    private List<String> fileNames;
    private List<Attach> attachs;
    /** 产品属性ID串 **/
    private String addInfos;
    /** 产品属性值串 **/
    private String addValues;
    /** 产品主要负责人ID **/
    private String mainPersons = "";
    /** 产品一般负责人ID **/
    private String persons = "";
    /** 产品主要负责人 **/
    private String mainPersonNames = "";
    /** 产品一般负责人 **/
    private String personNames = "";
    /** 产品服务 **/
    private IProductService<Product> productService;
    /** 产品资料服务 **/
    private IProductReferenceService<ProductReference> productReferenceService;
    /** 产品资料 **/
    private List<ProductReference> productReferences;
    /** 产品服务 **/
    private IPersonService<Person> personService;
    /** 产品服务 **/
    private LinkMethodService<LinkMethod> linkMethodService;
    /** 产品主要负责人 **/
    private List<Person> lMainPerson;
    /** 产品一般负责人 **/
    private List<Person> lGenPersons;
    /** 福建省产品目录定义服务 **/
    private IProductSortService productSortService;
    /** 产品目录 **/
    private ProductSort productSort;
    /** 福建省产品目录服务 **/
    private IProductRefSortService productRefSortService;
    /** 数据字典服务 **/
    private DictService<Dict> dictService;
    /** 数据字典类型服务 **/
    private DictTypeService<DictType> dictTypeService;
    /** 资料类型数据 **/
    private List<Dict> lRefType;
    /** 省产品目录 **/
    private ProductSort shProductSort;
    /** 集团产品目录 **/
    private ProductSort jtProductSort;
    /** 产品目录集合 **/
    private String [] productSortId;
    
    

    public DictTypeService<DictType> getDictTypeService()
    {
        return dictTypeService;
    }

    public void setDictTypeService(DictTypeService<DictType> dictTypeService)
    {
        this.dictTypeService = dictTypeService;
    }

    /**
     * 初始化业务数据
     * @return
     */
    @SuppressWarnings("unchecked")
    public String init()
    {
        if (product != null&&product.getId()!=null)
        {
            Criterion cond1 = Restrictions.eq("fileType", "pic");
            Criterion cond2 = Restrictions.eq("refEntityID", product.getId()
                    .toString());
            Criterion condAttach = Restrictions.and(cond1, cond2);
            attachs = attachService.findBy(condAttach);
            
            //获得产品所在目录
            try{
                Criterion condRef = Restrictions.eq("product", product.getId()+"");
                List<ProductRefSort> productRefSort = productRefSortService.findBy(condRef);
                ProductSort productSort=null;
                for(int i=0;i<productRefSort.size();i++){
                    String sortId=productRefSort.get(i).getSort();
                    productSort=(ProductSort)productSortService.findById(new Integer(sortId));
                    productSort.setName(this.findSortPath(productSort.getId()+""));
                    if("1".equals(productSort.getSortType())){
                        jtProductSort=productSort;
                    }else if("2".equals(productSort.getSortType())){
                        shProductSort=productSort;
                    }
                }
            }catch(Exception e){
                e.printStackTrace();
            }
        }else if(productSort!=null&&productSort.getId()>0){
            productSort=(ProductSort)productSortService.findById(new Integer(productSort.getId()));
            productSort.setName(this.findSortPath(productSort.getId()+""));
            if("1".equals(productSort.getSortType())){
                jtProductSort=productSort;
            }else if("2".equals(productSort.getSortType())){
                shProductSort=productSort;
            }
        }
        return SUCCESS;
    }

    /**
     * 新增或修改福建省产品目录类型数据
     * @return
     */
    public String findByPage()
    {
        /*
         * ActionContext ctx = ActionContext.getContext(); HttpServletResponse
         * response = (HttpServletResponse) ctx
         * .get(ServletActionContext.HTTP_RESPONSE); HttpServletRequest request
         * = (HttpServletRequest) ctx .get(ServletActionContext.HTTP_REQUEST);
         */
        HashMap<String, Object> conds = super.getConds();
        if (conds == null)
        {
            conds = new HashMap<String, Object>();
        }
        User currUser = ApplicationContextUtil.getUserContextObject()
                .getCurrUser();
        List<UserResource> modelMenus = ApplicationContextUtil
                .getUserContextObject().getUserResources();
        boolean searchAll = false;
        for (UserResource ur : modelMenus)
        {//
//            System.out.println(ur.getKey());
            if (ur.getKey().equals("OBJ_PRODUCT_MAN"))
            {
                searchAll = true;
                break;
            }
        }
        //如果第一次装置，默认参数
        if (pageControl == null)
        {
            pageControl = new PageControl();
        }
        if (!searchAll)
        {
            conds.put("creator", currUser.getUserID());
            conds.put("person", currUser.getPersonID());
            
            pageControl = productService.findByPage(conds, pageControl.getPageNo(),
                    pageControl.getPageSize());
            pageControl.setResults(this.offset(pageControl.getResults(), pageControl.getPageNo(), pageControl.getPageSize()));
        }else{
            super.findByPage();
        }
        
        return SUCCESS;
    }
    
    /**
     * 分页，从list中取一段数据
     * TODO 请输入方法说明
     * @param list
     * @param pageNo
     * @param pageSize
     * @return
     */
    public List offset(List list,int pageNo,int pageSize){
        int offset=0;
        int subNo=0;
        
        if(list.size()>=pageNo*pageSize){
            offset=(pageNo-1)*pageSize+1;
        }else{
            offset=list.size()/pageSize*pageSize;
        }
        if(list.size()>pageNo*pageSize){
            subNo=offset+pageSize;
        }else{
            subNo=list.size();
        }
        return list.subList(offset,subNo);
    }
    
    /**
     * 新增或修改福建省产品目录类型数据
     * @return
     */
    public String saveOrUpdate()
    {
        String[] delIDs = getContextObjects("delIDs");
        String[] mainPs = null;
        if (mainPersons != null && !mainPersons.equals(""))
        {
            mainPs = mainPersons.split(",");
        }
        String[] ps = null;
        if (persons != null && !persons.equals(""))
        {
            ps = persons.split(",");
        }
        
        productService.saveAll(product, addInfos, addValues, uploads,
                fileNames, delIDs, mainPs, ps, productSortId);
        init();
        findById();
        returnMsg = "保存操作已成功！";
        return SUCCESS;
    }

    /**
     * 新增或修改福建省产品目录类型数据
     * @return
     */
    public String saveOrUpdate2()
    {
        String[] delIDs = getContextObjects("delIDs");
        String[] mainPs = null;
        if (mainPersons != null && !mainPersons.equals(""))
        {
            mainPs = mainPersons.split(",");
        }
        String[] ps = null;
        if (persons != null && !persons.equals(""))
        {
            ps = persons.split(",");
        }
        productService.saveAll(product, addInfos, addValues, uploads,
                fileNames, delIDs, mainPs, ps);
        
        returnMsg = "保存操作已成功！";
        suFindById();
        return SUCCESS;
    }
    
    
    
    /**
     * 新增产品目录下的产品
     * @return
     */
    public String saveOrUpdateSortProduct()
    {
        String[] delIDs = getContextObjects("delIDs");
        String[] mainPs = null;

        if (mainPersons != null && !mainPersons.equals(""))
        {
            mainPs = mainPersons.split(",");
        }
        String[] ps = null;
        if (persons != null && !persons.equals(""))
        {
            ps = persons.split(",");
        }
        if(productSortId==null){
            productService.saveAll(product, addInfos, addValues, uploads,
                    fileNames, delIDs, mainPs, ps, productSort);
        }else{
            productService.saveAll(product, addInfos, addValues, uploads,
                    fileNames, delIDs, mainPs, ps, productSortId);
        }
        init();
        suFindById();
        returnMsg = "保存操作已成功！";
        return SUCCESS;
    }

    /**
     * 删除数据
     * @return
     */
    public String remove()
    {
        // try{
        productService.remove(product);
        returnMsg = "删除操作已成功！";
        return SUCCESS;
        // }catch(DataIntegrityViolationException e){
        // returnMsg="操作失败：数据正在使用中，不能删除！";
        // return "failure";
        // }
    }

    /**
     * 删除目录下产品
     * @return
     */
    public String deleteProduct()
    {
        ActionContext ctx = ActionContext.getContext();
        HttpServletResponse response = (HttpServletResponse) ctx
                .get(ServletActionContext.HTTP_RESPONSE);
        HttpServletRequest request = (HttpServletRequest) ctx
                .get(ServletActionContext.HTTP_REQUEST);
        response.setCharacterEncoding("gb2312");// 页面编码设置
        response.setContentType("text/xml");// 页面文件头格式
        try
        {
            baseService.remove(product);
            response.getWriter().write(MyList.getStr("true"));
        }
        catch (Exception e)
        {
            try
            {
                response.getWriter().write(MyList.getStr("false"));
            }
            catch (Exception ee)
            {
            }
            e.printStackTrace();

        }
        return null;
    }

    /**
     * 批量删除
     * @return
     */
    public String batchDel()
    {
        // try{
        String[] ids = getContextObjects("ids");
        productService.batchDel(ids);
        returnMsg = "批量删除操作已成功！";
        return SUCCESS;
        // }catch(DataIntegrityViolationException e){
        // returnMsg="操作失败：数据正在使用中，不能删除！";
        // return "failure";
        // }
    }

    /**
     * 根据关键值获取实体数据
     * @return
     */
    public String findById()
    {
        if (product != null && product.getId() != 0)
        {
            product = (D) baseService.findById(product.getId());
            Iterator it = product.getProductManagers().iterator();
            mainPersons = "";
            mainPersonNames = "";
            persons = "";
            personNames = "";
            while (it.hasNext())
            {
                ProductManager productManager = (ProductManager) it.next();
                Person person = productManager.getPerson();
                if (productManager.getIsPrimary().equals("1"))
                {
                    mainPersons += person.getId() + ",";
                    mainPersonNames += person.getName() + ",";
                }
                else
                {
                    persons += person.getId() + ",";
                    personNames += person.getName() + ",";
                }
            }
            if (mainPersons != null && mainPersons.length() > 0)
            {
                mainPersons = mainPersons
                        .substring(0, mainPersons.length() - 1);
                mainPersonNames = mainPersonNames.substring(0, mainPersonNames
                        .length() - 1);
            }
            if (persons != null && persons.length() > 0)
            {
                persons = persons.substring(0, persons.length() - 1);
                personNames = personNames
                        .substring(0, personNames.length() - 1);
            }
        }
        init();
        return SUCCESS;
    }

    /**
     * 组合查询条件
     * @return
     */
    public Criterion combineCond()
    {
        Criterion cond = null;
        if (super.getConds() != null)
        {
            // 遍历参数表
            Iterator i = super.getConds().entrySet().iterator();
            while (i.hasNext())
            {
                Entry entry = (Entry) i.next();
                String key = (String) entry.getKey();
                if (super.getConds().get(key) != null
                        && !StringUtils.isEmpty(super.getConds().get(key)
                                .toString()))
                {
                    // 根据实际情况做处理
                    Criterion temp = null;
                    if (key.equalsIgnoreCase("name"))
                    {
                        temp = Restrictions.like(key, "%"
                                + super.getConds().get(key).toString() + "%");
                    }
                    else
                    {
                        temp = Restrictions.eq(key, super.getConds().get(key));
                    }

                    if (cond == null)
                    {
                        cond = temp;
                    }
                    else
                    {
                        cond = Restrictions.and(cond, temp);
                    }
                }
            }
        }
        return cond;
    }

    /**
     * 获取产品信息进行展示
     * @return
     */
    @SuppressWarnings("unchecked")
    public String showProductInfoById()
    {
        if (product != null && product.getId() != 0)
        {
            product = (D) productService.findById(product.getId());
            String briefIntroduction = product.getBriefIntroduction();
            String description = product.getDescription();
            if (StringUtils.isNotEmpty(briefIntroduction))
            {
                briefIntroduction = briefIntroduction.replaceAll(" ", "&nbsp;");
                briefIntroduction = briefIntroduction.replaceAll("\n", "<br>");
                product.setBriefIntroduction(briefIntroduction);
            }
            if (StringUtils.isNotEmpty(description))
            {
                description = description.replaceAll(" ", "&nbsp;");
                description = description.replaceAll("\n", "<br>");
                product.setDescription(description);
            }

            Iterator it = product.getProductManagers().iterator();

            lMainPerson = new ArrayList<Person>();
            lGenPersons = new ArrayList<Person>();

            while (it.hasNext())
            {
                ProductManager productManager = (ProductManager) it.next();
                Person person = productManager.getPerson();

                // 获取联系方式
                Person managerInfo = (Person) personService.findById(person
                        .getId());
                List<LinkMethod> linkMethods = productService
                        .getPMLinkMethods(person);
                managerInfo.setLinkMethods(linkMethods);
                if (productManager.getIsPrimary().equals("1"))
                {
                    lMainPerson.add(managerInfo);
                }
                else
                {
                    lGenPersons.add(managerInfo);
                }
            }

            // 获取产品资料信息，包括业务管理规范和产品说明书、产品视图
            productReferences=productService.findProdRefsById(product.getId());
        }

        // 图片展示
        init();

        return SUCCESS;
    }

    /**
     * 统一维护获取产品信息进行展示
     * @return
     */
    public String suFindById()
    {
        boolean flag=false;
        if (product != null && product.getId() != 0)
        {
            product = (D) productService.findById(product.getId());
            String briefIntroduction = product.getBriefIntroduction();
            String description = product.getDescription();
            if (StringUtils.isNotEmpty(briefIntroduction))
            {
//                briefIntroduction = briefIntroduction.replaceAll(" ", "&nbsp;");
//                briefIntroduction = briefIntroduction.replaceAll("\n", "<br>");
                product.setBriefIntroduction(briefIntroduction);
            }
            if (StringUtils.isNotEmpty(description))
            {
//                description = description.replaceAll(" ", "&nbsp;");
//                description = description.replaceAll("\n", "<br>");
                product.setDescription(description);
            }

            Iterator it = product.getProductManagers().iterator();

            lMainPerson = new ArrayList<Person>();
            lGenPersons = new ArrayList<Person>();

            ////当操作人为当前产品的产品经理时，可编辑；否则，不允许编辑，只查看-pany-091016
            User currUser = ApplicationContextUtil.getUserContextObject().getCurrUser();
            int personId=0;
            if(currUser!=null&&currUser.getPerson()!=null){
                personId=currUser.getPerson().getId();
            }
            
            while (it.hasNext())
            {
                ProductManager productManager = (ProductManager) it.next();
                Person person = productManager.getPerson();
                //当当前操作人是产品经理时，允许编辑
                if(personId==person.getId()){
                    flag=true;
                }
                
                // 获取联系方式
                Person managerInfo = (Person) personService.findById(person
                        .getId());
                List<LinkMethod> linkMethods = productService
                        .getPMLinkMethods(person);
                managerInfo.setLinkMethods(linkMethods);
                if (productManager.getIsPrimary().equals("1"))
                {
                    lMainPerson.add(managerInfo);
                    mainPersons += person.getId() + ",";
                    mainPersonNames += person.getName() + ",";
                }
                else
                {
                    lGenPersons.add(managerInfo);
                    persons += person.getId() + ",";
                    personNames += person.getName() + ",";
                }
            }
            
            if (mainPersons != null && mainPersons.length() > 0)
            {
                mainPersons = mainPersons
                        .substring(0, mainPersons.length() - 1);
                mainPersonNames = mainPersonNames.substring(0, mainPersonNames
                        .length() - 1);
            }
            if (persons != null && persons.length() > 0)
            {
                persons = persons.substring(0, persons.length() - 1);
                personNames = personNames
                        .substring(0, personNames.length() - 1);
            }
            
            
        }

        // 图片展示
        init();
        if(product == null || product.getId() == 0){
            return SUCCESS;
        }
        
        ////当操作人为当前产品的产品经理时，可编辑；否则，不允许编辑，只查看-pany-091016
        if(!flag){
            return "read";
        }
        
        // 产品资料
        getProductReference();
        Criterion cond = Restrictions.eq("product.id", product.getId());
        List<ProductReference> lpr = productReferenceService.findBy(cond);
        List<ProductReference> result = new ArrayList<ProductReference>();
        if (lpr != null && lpr.size() > 0)
        {
            for (ProductReference pr : lpr)
            {
                Criterion cond1 = Restrictions.eq("refEntity", pr.getClass()
                        .getName());
                Criterion cond2 = Restrictions.eq("refEntityID", pr.getId()
                        .toString());
                Criterion condAttach = Restrictions.and(cond1, cond2);
                pr.setAttachs(attachService.findBy(condAttach));
                for(Dict dict:lRefType){
                    if(dict.getId().equals(pr.getReferenceType().getId())){
                        lRefType.remove(dict);
                        break;
                    }
                }
                result.add(pr);
            }
        }
        productReferences = result;
        return SUCCESS;
    }

    
    public void getProductReference(){
        // 根据实体名称获取字典类型
        String dtKey = new ProductReference().getClass().getSimpleName();
        Criterion condDt = Restrictions.eq("keyValue", dtKey.toUpperCase());
        List<DictType> ldt = this.dictTypeService.findBy(condDt);
        if (ldt != null && ldt.size() > 0)
        {
            DictType dictType = (DictType) ldt.get(0);
            Criterion cond = Restrictions.eq("dictType.id", dictType.getId());
            lRefType = dictService.findBy(cond);
        }
        else
        {
            lRefType = new ArrayList<Dict>();
        }
    }
    
    /**
     * 根据产品名称获取产品资料信息
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchPR()
    {
        return SUCCESS;
    }

    /**
     * 产品类型树
     * @return
     */
    public String findTree()
    {
        ActionContext ctx = ActionContext.getContext();
        HttpServletResponse response = (HttpServletResponse) ctx
                .get(ServletActionContext.HTTP_RESPONSE);
        HttpServletRequest request = (HttpServletRequest) ctx
                .get(ServletActionContext.HTTP_REQUEST);
        String type = request.getParameter("type");
        List<D> ls = super.findBy();
        String xml = MyList.getProductTree(ls, type);
        response.setCharacterEncoding("gb2312");// 页面编码设置
        response.setContentType("text/xml");// 页面文件头格式
        try
        {
            response.getWriter().write(xml);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 产品查询
     * @return
     */
    public String findView()
    {
        ActionContext ctx = ActionContext.getContext();
        HttpServletResponse response = (HttpServletResponse) ctx
                .get(ServletActionContext.HTTP_RESPONSE);
        try
        {
            HashMap<String, Object> oldConds = super.getConds();
            if (oldConds != null)
            {
                HashMap<String, Object> newConds = new HashMap();
                Iterator i = oldConds.entrySet().iterator();
                while (i.hasNext())
                {
                    Entry entry = (Entry) i.next();
                    String key = (String) entry.getKey();
                    if (oldConds.get(key) != null)
                    {
                        String str = oldConds.get(key).toString();
                        str = new String(str.getBytes("iso8859-1"), "utf-8");
                        if (str != null && !str.equals(""))
                        {
                            newConds.put(key, str);
                        }
                    }
                }
                super.setConds(newConds);
            }
            products = baseService.findBy(combineCond());
            String xml = MyList.getAll(products);
            response.setCharacterEncoding("gb2312");// 页面编码设置
            response.setContentType("text/xml");// 页面文件头格式
            response.getWriter().write(xml);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }
    
    
    /**
     * 产品类型视图-pany-add-090504
     * @return
     */
    public String productView()
    {
        products = baseService.findBy(combineCond());
        try
        {
            for (int i = 0; i < products.size() && i < 10; i++)
            {
                Product prod = null;
                Criterion cond = null;
                List<ProductRefSort> productRefSort = null;
                ResultSet rs = null;
                List list = new ArrayList();
                prod = products.get(i);
                cond = Restrictions.eq("product", prod.getId().toString());
                productRefSort = productRefSortService.findBy(cond);
                for (int j = 0; j < productRefSort.size(); j++)
                {
                    Map prodSorts = new HashMap();
                    String str = productSortService
                            .findAllSortById(productRefSort.get(j).getSort());
                    prodSorts.put("sortName", str);
                    list.add(prodSorts);
                }
                prod.setProdSorts(list);
                Criterion cond1 = Restrictions.eq("fileType", "pic");
                Criterion cond2 = Restrictions.eq("refEntityID", prod.getId()
                        .toString());
                Criterion condAttach = Restrictions.and(cond1, cond2);
                prod.setAttachs(attachService.findBy(condAttach));
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return SUCCESS;
    }
    
    public String findSortPath(String sortId){
        String str = productSortService.findAllSortById(sortId+"")+"";
        str=str.replace("集团产品目录:", "");
        str=str.replace("福建省产品目录:", "");
        str=str.replace(" -> ", "/");
        return str;
    }
    
    public String listSortPathById(){
        ActionContext ctx = ActionContext.getContext();        
        HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);   
        String str = findSortPath(productSort.getId()+"");
        String xml=MyList.getStr(str);
        response.setCharacterEncoding("gb2312");//页面编码设置
        response.setContentType("text/xml");//页面文件头格式
//        System.out.println(xml);
        try{
            response.getWriter().write(xml);
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }
    
    public String findNewProduct()
    {
        // //获得新的产品信息
        Criterion cond = null;
        cond = Restrictions.eq("isNew", "1");
        products = baseService.findBy(cond);
        for (Product prod : products)
        {
            if (prod != null)
            {
                Criterion cond1 = Restrictions.like("fileType", "pic");
                Criterion cond2 = Restrictions.like("refEntityID", prod.getId()
                        .toString());
                Criterion condAttach = Restrictions.and(cond1, cond2);
                List<Attach> attachs = attachService.findBy(condAttach);
                if (attachs != null && attachs.size() > 0)
                {
                    List<Attach> list = new ArrayList();
                    list.add(attachs.get(0));
                    prod.setAttachs(list);
                }
            }
        }
        return SUCCESS;
    }

    /**
     * 转跳到综合修改页面
     * @return
     */
    public String singleupdate()
    {
        return SUCCESS;
    }

    /**
     * 获取福建省产品目录类型
     * @return
     */
    public D getProduct()
    {
        return product;
    }

    /**
     * 设置福建省产品目录类型
     * @param dict
     */
    public void setProduct(D product)
    {
        this.product = product;
    }

    /**
     * 获取结果集
     * @return
     */
    public List<D> getProducts()
    {
        return products;
    }

    /**
     * 设置结果集
     * @param dicts
     */
    public void setProducts(List<D> products)
    {
        this.products = products;
    }

    /**
     * 获取附件服务
     * @return the attachService
     */
    public IAttachService getAttachService()
    {
        return attachService;
    }

    /**
     * 设置附件服务
     * @param attachService the attachService to set
     */
    public void setAttachService(IAttachService attachService)
    {
        this.attachService = attachService;
    }

    public List<File> getUpload()
    {
        return uploads;
    }

    public void setUpload(List<File> uploads)
    {
        this.uploads = uploads;
    }

    public List<String> getUploadFileName()
    {
        return fileNames;
    }

    public void setUploadFileName(List<String> fileNames)
    {
        this.fileNames = fileNames;
    }

    public String getAddInfos()
    {
        return addInfos;
    }

    public void setAddInfos(String addInfos)
    {
        this.addInfos = addInfos;
    }

    public IProductService getProductService()
    {
        return productService;
    }

    public void setProductService(IProductService productService)
    {
        this.productService = productService;
    }

    public String getAddValues()
    {
        return addValues;
    }

    public void setAddValues(String addValues)
    {
        this.addValues = addValues;
    }

    public String getMainPersons()
    {
        return mainPersons;
    }

    public void setMainPersons(String mainPersons)
    {
        this.mainPersons = mainPersons;
    }

    public String getPersons()
    {
        return persons;
    }

    public void setPersons(String persons)
    {
        this.persons = persons;
    }

    public String getMainPersonNames()
    {
        return mainPersonNames;
    }

    public void setMainPersonNames(String mainPersonNames)
    {
        this.mainPersonNames = mainPersonNames;
    }

    public String getPersonNames()
    {
        return personNames;
    }

    public void setPersonNames(String personNames)
    {
        this.personNames = personNames;
    }

    public List<File> getUploads()
    {
        return uploads;
    }

    public void setUploads(List<File> uploads)
    {
        this.uploads = uploads;
    }

    public List<String> getFileNames()
    {
        return fileNames;
    }

    public void setFileNames(List<String> fileNames)
    {
        this.fileNames = fileNames;
    }

    public List<Attach> getAttachs()
    {
        return attachs;
    }

    public void setAttachs(List<Attach> attachs)
    {
        this.attachs = attachs;
    }

    public static int getBUFFER_SIZE()
    {
        return BUFFER_SIZE;
    }

    /**
     * @return the personService
     */
    public IPersonService getPersonService()
    {
        return personService;
    }

    /**
     * @param personService the personService to set
     */
    public void setPersonService(IPersonService personService)
    {
        this.personService = personService;
    }

    /**
     * @return the lMainPerson
     */
    public List<Person> getLMainPerson()
    {
        return lMainPerson;
    }

    /**
     * @param mainPerson the lMainPerson to set
     */
    public void setLMainPerson(List<Person> mainPerson)
    {
        lMainPerson = mainPerson;
    }

    /**
     * @return the lGenPersons
     */
    public List<Person> getLGenPersons()
    {
        return lGenPersons;
    }

    /**
     * @param genPersons the lGenPersons to set
     */
    public void setLGenPersons(List<Person> genPersons)
    {
        lGenPersons = genPersons;
    }

    /**
     * @return the linkMethodService
     */
    public LinkMethodService getLinkMethodService()
    {
        return linkMethodService;
    }

    /**
     * @param linkMethodService the linkMethodService to set
     */
    public void setLinkMethodService(LinkMethodService linkMethodService)
    {
        this.linkMethodService = linkMethodService;
    }

    /**
     * @return the productReferenceService
     */
    public IProductReferenceService<ProductReference> getProductReferenceService()
    {
        return productReferenceService;
    }

    /**
     * @param productReferenceService the productReferenceService to set
     */
    public void setProductReferenceService(
            IProductReferenceService<ProductReference> productReferenceService)
    {
        this.productReferenceService = productReferenceService;
    }

    public IProductSortService getProductSortService()
    {
        return productSortService;
    }

    public void setProductSortService(IProductSortService productSortService)
    {
        this.productSortService = productSortService;
    }

    public IProductRefSortService getProductRefSortService()
    {
        return productRefSortService;
    }

    public void setProductRefSortService(
            IProductRefSortService productRefSortService)
    {
        this.productRefSortService = productRefSortService;
    }

    public ProductSort getProductSort()
    {
        return productSort;
    }

    public void setProductSort(ProductSort productSort)
    {
        this.productSort = productSort;
    }

    public List<ProductReference> getProductReferences()
    {
        return productReferences;
    }

    public void setProductReferences(List<ProductReference> productReferences)
    {
        this.productReferences = productReferences;
    }

    /**
     * @return the dictService
     */
    public DictService<Dict> getDictService()
    {
        return dictService;
    }

    /**
     * @param dictService the dictService to set
     */
    public void setDictService(DictService<Dict> dictService)
    {
        this.dictService = dictService;
    }

    public List<Dict> getLRefType()
    {
        return lRefType;
    }

    public void setLRefType(List<Dict> refType)
    {
        lRefType = refType;
    }

    public ProductSort getJtProductSort()
    {
        return jtProductSort;
    }

    public void setJtProductSort(ProductSort jtProductSort)
    {
        this.jtProductSort = jtProductSort;
    }

    public ProductSort getShProductSort()
    {
        return shProductSort;
    }

    public void setShProductSort(ProductSort shProductSort)
    {
        this.shProductSort = shProductSort;
    }

    public String[] getProductSortId()
    {
        return productSortId;
    }

    public void setProductSortId(String[] productSortId)
    {
        this.productSortId = productSortId;
    }

}
